/*****************************************************************
**                                                              **
**  Copyright (C) 2004 Amlogic,Inc.                             **
**  All rights reserved                                         **
**        Filename : aw_vob_app.c /Project:AVOS                ** 
**        Revision : 1.0                                        **
**                                                              **
*****************************************************************/
#ifndef __AW_VOB_APP_H_
#define __AW_VOB_APP_H_
 
#include "includes.h"
#include "aw_windows.h"
#include "app.h"
#include "user.h"
#include <aw_playlist2.h>
#include "vob_define.h"

extern Playlist_t *vob_playlist;

INT8U VobCmdResponse(AWMSG *pMsg, PCMDSET cmd_set) ;

extern int PlayVOBFile(char *file_name);

int RunVOBPlayer(Playlist_t *playlist) ;

void AWVOBKeyDo(INT32S key) ;

void AWVOBKeyProcess(AWMSG *pMsg) ;

void AWVOBNotificationProcess(AWMSG *pMsg) ;

void AWVOBMsgProcess(AWMSG *pMsg) ;

void AWVOBQuitProcess(void); 

int PreviewVobPlayer(char *filename);

void vob_play_preview(char *filename) ;

INT8U GetVOBInfo(char *file_name, VIDEO_INFO *video_info);

#define PROBE_READ_SIZE 4096
//#define MAX_PROBE_SIZE  0x40000
#define MAX_PROBE_SIZE  0x100000
#define MINUS_MAX_PROBE_SIZE 0x100000
#define SEQ_START_CODE_FOUND        0x01
#define VIDEO_ID_FOUND              0x02
#define AUDIO_ID_FOUND              0x04
#define STUFF_BYTES_LENGTH 256

typedef struct {
    int    play_start;             /* file offset */
} reload_t;       
    
#define MAX_AUDIO_STREAM    8
typedef struct {
    int         fd_video;
    int         fd_decoder;
    int         fd_target;
    OS_EVENT   *audio_if;

    vob_status_e stat;                                  /* current status */
    vob_status_e breakstat;                             /* final target status */ 
    unsigned    pending_command;                        /* non seamless change to seamless switch pending command */
    unsigned    pending_command_param;
        
    unsigned    video_id;                               /* current video ID */
    unsigned    audio_id[MAX_AUDIO_STREAM];             /* current audio ID */
    unsigned    cur_audio;                              /* current playing audio stream index */

    /* non_seamless play information */
    int         ns_playspeed;                           /* FF,BF speed */

    reload_t    reload;                                 /* vob restart non_seamless play information */

    unsigned char *chunk_cache_data;

    AVTimer_t   timer;
} play_t;

typedef enum {
    VOB_AUDIO_NULL = 0,
    VOB_AUDIO_MPG,
    VOB_AUDIO_AC3,
    VOB_AUDIO_LPCM,
    VOB_AUDIO_DTS,
    VOB_AUDIO_SDDS
} vob_audio_t;

typedef struct {
    PAPPTASKARG app;                    /* application handle */

    play_t      play;                   /* playback control and running info */

    unsigned    total_audio_stream;     /* total audio stream number */
    unsigned    total_index_num;        /* index size */
    
    unsigned    height;                 /* video height */
    unsigned    width;                  /* video width */
    unsigned    frame_rate;             /* frame rate */
    vob_audio_t audio_id[MAX_AUDIO_STREAM];        /* audio stream ID */

    EventSubscriber_t *listener;        /* event loop listener */

    unsigned char *logo;                /* logo to display before the app quits */
    unsigned    logosize;
    
    unsigned    ns_start_datasrc_position;
    unsigned    cur_datasrc_position;
    unsigned    last_datasrc_position;
    unsigned    datasrc_remain_level;
    DataSrc_t   datasrc;                /* data port */
    
    unsigned    block_audio;
    unsigned    vbuf_size;
    unsigned    vbuf_level;
    unsigned    vbuf_watchdog;
    unsigned    sequenceheader_size;
    unsigned char *sequenceheader;
    unsigned    first_vpts;
    unsigned    end_pending;
    unsigned    parser_type;
    int      auxiliary_info[MAX_AUDIO_STREAM];
    char     video_format;              //0 -- mpeg2  1 -- mpeg1
    int      scroffset;
    unsigned bps;
    unsigned view_position; //lower 16:x high 16:y
    unsigned view_size;// lower 16:width    high 16:height
    unsigned preview_flag; //bit0:preview_flag time bit1:audio_mute
    unsigned char* hvd_decrypt_info;
    unsigned char hvd_attr[2];
    unsigned char ff_fb_read_size_factor;
    unsigned char enc_flag;
    unsigned char wideoption_wide;
	unsigned char mpeg_audio_flag;	// if mpeg audio found, this means layer 1,2,3 for *.MPG file
} vob_t;

typedef struct vob_fileinfo{
	double totaltime;
	unsigned  video_codec;//mpeg1,mpeg2
	unsigned    video_kbps;
	unsigned    audio_kbps;
	unsigned short   width;//video resolution
	unsigned short   height;//video resolution
	unsigned    audio_codec;//mpeg/lpcm/ac3/dts
	unsigned    audio_channels;
	unsigned    chan_status;
	unsigned    file_size;
}VOBINFO;

#define OSD_HALF_SIZE 720*480/8

typedef struct {
	int left;
	int top;
	int width;
	int height;	
	unsigned short colorcode;
	unsigned short  contrast;
	unsigned prtData;
	unsigned cls;
} vob_subtitle_showdata;

#endif //__AW_VOB_APP_H_
